Skip to content

Revert "Feat/178 about ordering"#230

Merged
junglesub merged 1 commit intomainfrom
revert-188-feat/178-about-ordering
Jun 6, 2025
Merged

Revert "Feat/178 about ordering"#230
junglesub merged 1 commit intomainfrom
revert-188-feat/178-about-ordering

Conversation

@junglesub
Copy link
Member

@junglesub junglesub commented Jun 6, 2025

Reverts #188

Summary by CodeRabbit

  • 버그 수정
    • 노드 그룹, 노드, 섹션 생성·수정·삭제 시 적용되던 자동 순서 재정렬 기능이 제거되었습니다. 이제 항목 순서가 자동으로 조정되지 않습니다.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 6, 2025

Walkthrough

이 변경사항은 NodeGroup, Node, Section 서비스 구현에서 생성, 수정, 소프트 삭제 시 수행되던 정렬(reorder) 및 순서 조정 로직을 모두 제거하였습니다. 각 서비스의 CRUD 메서드는 이제 단순히 엔티티를 저장, 수정, 삭제만 수행하며, 정렬 관련 메서드와 관련 import도 삭제되었습니다.

Changes

파일 경로 변경 요약
.../service/impl/NodeGroupServiceImpl.java
.../NodeServiceImpl.java
.../SectionServiceImpl.java
생성, 수정, 소프트 삭제 시 정렬 및 순서 조정 로직 제거. reorder 관련 private 메서드 및 import 삭제.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant ServiceImpl

    Client->>ServiceImpl: create/update/deleteSoft 요청
    ServiceImpl-->>ServiceImpl: 엔티티 저장/수정/삭제 (정렬 로직 없음)
    ServiceImpl-->>Client: 결과 반환
Loading

Possibly related PRs

  • Feat/178 about ordering #188: 이 PR은 node group, node, section의 reorder-and-persist 로직을 도입 및 중앙집중화했으며, 본 PR은 해당 정렬 통합 로직을 제거하는 작업과 직접적으로 연관되어 있습니다.

Suggested labels

be

Suggested reviewers

  • Callein

Poem

🐰
순서 정렬, 안녕!
CRUD만 남아 깔끔해진 길,
노드와 섹션, 그룹도
이제는 단순하게,
토끼는 깡총깡총,
코드도 가벼워졌네!
🥕


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-project-automation github-project-automation bot moved this to Backlog in HANDONG-CMS Jun 6, 2025
@coderabbitai coderabbitai bot added the be Backend label Jun 6, 2025
@junglesub junglesub moved this from Backlog to In review in HANDONG-CMS Jun 6, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8536be5 and d2d6433.

📒 Files selected for processing (3)
  • src/main/java/com/handongapp/cms/service/impl/NodeGroupServiceImpl.java (2 hunks)
  • src/main/java/com/handongapp/cms/service/impl/NodeServiceImpl.java (2 hunks)
  • src/main/java/com/handongapp/cms/service/impl/SectionServiceImpl.java (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (3)
src/main/java/com/handongapp/cms/service/impl/NodeGroupServiceImpl.java (1)
src/main/java/com/handongapp/cms/dto/v1/NodeGroupDto.java (1)
  • NodeGroupDto (15-146)
src/main/java/com/handongapp/cms/service/impl/SectionServiceImpl.java (1)
src/main/java/com/handongapp/cms/dto/v1/SectionDto.java (1)
  • SectionDto (12-116)
src/main/java/com/handongapp/cms/service/impl/NodeServiceImpl.java (1)
src/main/java/com/handongapp/cms/dto/v1/NodeDto.java (1)
  • NodeDto (10-121)
🔇 Additional comments (4)
src/main/java/com/handongapp/cms/service/impl/NodeServiceImpl.java (2)

44-49: 변경사항이 적절합니다.

노드 생성 로직이 단순화되었으며, 불필요한 재정렬 로직이 제거되었습니다.


70-78: ⚠️ Potential issue

엔티티 변경사항이 저장되지 않습니다.

req.applyTo(entity)로 엔티티를 수정한 후 저장하지 않고 있습니다. @Transactional이 있어 dirty checking으로 자동 저장될 수 있지만, 명시적으로 저장하는 것이 안전합니다.

다음과 같이 수정하세요:

 public NodeDto.Response update(String nodeId, NodeDto.UpdateRequest req) {
     TbNode entity = nodeRepository.findByIdAndDeleted(nodeId, "N")
             .orElseThrow(() -> new EntityNotFoundException("Node not found with id: " + nodeId));
     if (req.getData() != null) {
//            NodeDataValidator.validate(entity.getType(), req.getData());
     }
     req.applyTo(entity);
+    nodeRepository.save(entity);
     return NodeDto.Response.from(entity);
 }

Likely an incorrect or invalid review comment.

src/main/java/com/handongapp/cms/service/impl/NodeGroupServiceImpl.java (1)

49-53: 변경사항이 적절합니다.

노드 그룹 생성 로직이 단순화되었으며, 불필요한 재정렬 로직이 제거되었습니다.

src/main/java/com/handongapp/cms/service/impl/SectionServiceImpl.java (1)

23-27: 변경사항이 적절합니다.

섹션 생성 로직이 단순화되었으며, 불필요한 재정렬 로직이 제거되었습니다.

Comment on lines 82 to 86
public void deleteSoft(String nodeId) {
TbNode entity = nodeRepository.findByIdAndDeleted(nodeId, "N")
.orElseThrow(() -> new EntityNotFoundException("Node not found with id: " + nodeId));

String nodeGroupId = entity.getNodeGroupId();
entity.setDeleted("Y");
entity.setOrder(null); // Mark order as irrelevant for soft-deleted items
nodeRepository.save(entity); // Persist the soft deletion

// Reorder remaining active nodes
reorderAndPersistNodes(nodeGroupId, null, null);
}

private TbNode reorderAndPersistNodes(String nodeGroupId, @Nullable TbNode targetNode, @Nullable Integer requestedOrderForTarget) {
List<TbNode> currentNodesInDb = nodeRepository.findByNodeGroupIdAndDeletedOrderByOrderAsc(nodeGroupId, "N");

List<TbNode> nodesToProcess = new ArrayList<>();
boolean isTargetNew = (targetNode != null && targetNode.getId() == null);

for (TbNode n : currentNodesInDb) {
if (targetNode != null && n.getId() != null && n.getId().equals(targetNode.getId()) && !isTargetNew) {
continue;
}
nodesToProcess.add(n);
}

TbNode nodeToReturn = targetNode;

if (targetNode != null) {
int insertionIndex;
Integer effectiveOrder = requestedOrderForTarget;

if (effectiveOrder == null) {
if (!isTargetNew) {
effectiveOrder = targetNode.getOrder();
}
}

if (effectiveOrder == null) {
insertionIndex = nodesToProcess.size();
} else {
insertionIndex = Math.max(0, Math.min(effectiveOrder, nodesToProcess.size()));
}
nodesToProcess.add(insertionIndex, targetNode);
}

for (int i = 0; i < nodesToProcess.size(); i++) {
TbNode node = nodesToProcess.get(i);
node.setOrder(i);
}

if (!nodesToProcess.isEmpty()) {
nodeRepository.saveAll(nodesToProcess);
}

return nodeToReturn;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

소프트 삭제가 저장되지 않습니다.

엔티티의 deleted 플래그를 설정한 후 저장하지 않고 있습니다.

다음과 같이 수정하세요:

 public void deleteSoft(String nodeId) {
     TbNode entity = nodeRepository.findByIdAndDeleted(nodeId, "N")
             .orElseThrow(() -> new EntityNotFoundException("Node not found with id: " + nodeId));
     entity.setDeleted("Y");
+    nodeRepository.save(entity);
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
public void deleteSoft(String nodeId) {
TbNode entity = nodeRepository.findByIdAndDeleted(nodeId, "N")
.orElseThrow(() -> new EntityNotFoundException("Node not found with id: " + nodeId));
String nodeGroupId = entity.getNodeGroupId();
entity.setDeleted("Y");
entity.setOrder(null); // Mark order as irrelevant for soft-deleted items
nodeRepository.save(entity); // Persist the soft deletion
// Reorder remaining active nodes
reorderAndPersistNodes(nodeGroupId, null, null);
}
private TbNode reorderAndPersistNodes(String nodeGroupId, @Nullable TbNode targetNode, @Nullable Integer requestedOrderForTarget) {
List<TbNode> currentNodesInDb = nodeRepository.findByNodeGroupIdAndDeletedOrderByOrderAsc(nodeGroupId, "N");
List<TbNode> nodesToProcess = new ArrayList<>();
boolean isTargetNew = (targetNode != null && targetNode.getId() == null);
for (TbNode n : currentNodesInDb) {
if (targetNode != null && n.getId() != null && n.getId().equals(targetNode.getId()) && !isTargetNew) {
continue;
}
nodesToProcess.add(n);
}
TbNode nodeToReturn = targetNode;
if (targetNode != null) {
int insertionIndex;
Integer effectiveOrder = requestedOrderForTarget;
if (effectiveOrder == null) {
if (!isTargetNew) {
effectiveOrder = targetNode.getOrder();
}
}
if (effectiveOrder == null) {
insertionIndex = nodesToProcess.size();
} else {
insertionIndex = Math.max(0, Math.min(effectiveOrder, nodesToProcess.size()));
}
nodesToProcess.add(insertionIndex, targetNode);
}
for (int i = 0; i < nodesToProcess.size(); i++) {
TbNode node = nodesToProcess.get(i);
node.setOrder(i);
}
if (!nodesToProcess.isEmpty()) {
nodeRepository.saveAll(nodesToProcess);
}
return nodeToReturn;
}
public void deleteSoft(String nodeId) {
TbNode entity = nodeRepository.findByIdAndDeleted(nodeId, "N")
.orElseThrow(() -> new EntityNotFoundException("Node not found with id: " + nodeId));
entity.setDeleted("Y");
nodeRepository.save(entity);
}
🤖 Prompt for AI Agents
In src/main/java/com/handongapp/cms/service/impl/NodeServiceImpl.java around
lines 82 to 86, the soft delete method sets the deleted flag on the entity but
does not persist this change. To fix this, after setting the deleted flag to
"Y", call the save method on nodeRepository to save the updated entity.

Comment on lines 83 to 87
public void deleteSoft(String id) {
TbNodeGroup entity = nodeGroupRepository.findByIdAndDeleted(id, "N")
.orElseThrow(() -> new EntityNotFoundException("NodeGroup not found with id: " + id));

String sectionId = entity.getSectionId();
entity.setDeleted("Y");
entity.setOrder(null); // Mark order as irrelevant for soft-deleted items
nodeGroupRepository.save(entity); // Persist the soft deletion

// Reorder remaining active node groups
reorderAndPersistNodeGroups(sectionId, null, null);
}

private TbNodeGroup reorderAndPersistNodeGroups(String sectionId, @Nullable TbNodeGroup targetNodeGroup, @Nullable Integer requestedOrderForTarget) {
List<TbNodeGroup> currentNodeGroupsInDb = nodeGroupRepository.findBySectionIdAndDeletedOrderByOrderAsc(sectionId, "N");

List<TbNodeGroup> nodeGroupsToProcess = new ArrayList<>();
boolean isTargetNew = (targetNodeGroup != null && targetNodeGroup.getId() == null);

for (TbNodeGroup ng : currentNodeGroupsInDb) {
if (targetNodeGroup != null && ng.getId() != null && ng.getId().equals(targetNodeGroup.getId()) && !isTargetNew) {
continue;
}
nodeGroupsToProcess.add(ng);
}

TbNodeGroup nodeGroupToReturn = targetNodeGroup;

if (targetNodeGroup != null) {
int insertionIndex;
Integer effectiveOrder = requestedOrderForTarget;

if (effectiveOrder == null) {
if (!isTargetNew) {
effectiveOrder = targetNodeGroup.getOrder();
}
}

if (effectiveOrder == null) {
insertionIndex = nodeGroupsToProcess.size();
} else {
insertionIndex = Math.max(0, Math.min(effectiveOrder, nodeGroupsToProcess.size()));
}
nodeGroupsToProcess.add(insertionIndex, targetNodeGroup);
}

for (int i = 0; i < nodeGroupsToProcess.size(); i++) {
TbNodeGroup nodeGroup = nodeGroupsToProcess.get(i);
nodeGroup.setOrder(i);
}

if (!nodeGroupsToProcess.isEmpty()) {
nodeGroupRepository.saveAll(nodeGroupsToProcess);
}

return nodeGroupToReturn;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

소프트 삭제가 저장되지 않습니다.

엔티티의 deleted 플래그를 설정한 후 저장하지 않고 있습니다.

다음과 같이 수정하세요:

 public void deleteSoft(String id) {
     TbNodeGroup entity = nodeGroupRepository.findByIdAndDeleted(id, "N")
             .orElseThrow(() -> new EntityNotFoundException("NodeGroup not found with id: " + id));
     entity.setDeleted("Y");
+    nodeGroupRepository.save(entity);
 }
🤖 Prompt for AI Agents
In src/main/java/com/handongapp/cms/service/impl/NodeGroupServiceImpl.java
around lines 83 to 87, the soft delete method sets the deleted flag on the
entity but does not save the updated entity back to the repository. Fix this by
calling the save method on nodeGroupRepository with the modified entity after
setting the deleted flag to "Y" to persist the change.

Comment on lines 74 to 79
public NodeGroupDto.Response update(String id, NodeGroupDto.UpdateRequest req) {
TbNodeGroup entityToUpdate = nodeGroupRepository.findByIdAndDeleted(id, "N")
TbNodeGroup entity = nodeGroupRepository.findByIdAndDeleted(id, "N")
.orElseThrow(() -> new EntityNotFoundException("NodeGroup not found with id: " + id));

String sectionId = entityToUpdate.getSectionId();

// Apply changes from DTO. Assumes req.applyTo updates entityToUpdate.order if req.getOrder() is not null.
req.applyTo(entityToUpdate);

// entityToUpdate.getOrder() will be the requested new order if specified in DTO, or original order if not.
TbNodeGroup updatedEntity = reorderAndPersistNodeGroups(sectionId, entityToUpdate, entityToUpdate.getOrder());
return NodeGroupDto.Response.from(updatedEntity);
req.applyTo(entity);
return NodeGroupDto.Response.from(entity);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

엔티티 변경사항이 저장되지 않습니다.

req.applyTo(entity)로 엔티티를 수정한 후 저장하지 않고 있습니다.

다음과 같이 수정하세요:

 public NodeGroupDto.Response update(String id, NodeGroupDto.UpdateRequest req) {
     TbNodeGroup entity = nodeGroupRepository.findByIdAndDeleted(id, "N")
             .orElseThrow(() -> new EntityNotFoundException("NodeGroup not found with id: " + id));
     req.applyTo(entity);
+    nodeGroupRepository.save(entity);
     return NodeGroupDto.Response.from(entity);
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
public NodeGroupDto.Response update(String id, NodeGroupDto.UpdateRequest req) {
TbNodeGroup entityToUpdate = nodeGroupRepository.findByIdAndDeleted(id, "N")
TbNodeGroup entity = nodeGroupRepository.findByIdAndDeleted(id, "N")
.orElseThrow(() -> new EntityNotFoundException("NodeGroup not found with id: " + id));
String sectionId = entityToUpdate.getSectionId();
// Apply changes from DTO. Assumes req.applyTo updates entityToUpdate.order if req.getOrder() is not null.
req.applyTo(entityToUpdate);
// entityToUpdate.getOrder() will be the requested new order if specified in DTO, or original order if not.
TbNodeGroup updatedEntity = reorderAndPersistNodeGroups(sectionId, entityToUpdate, entityToUpdate.getOrder());
return NodeGroupDto.Response.from(updatedEntity);
req.applyTo(entity);
return NodeGroupDto.Response.from(entity);
}
public NodeGroupDto.Response update(String id, NodeGroupDto.UpdateRequest req) {
TbNodeGroup entity = nodeGroupRepository.findByIdAndDeleted(id, "N")
.orElseThrow(() -> new EntityNotFoundException("NodeGroup not found with id: " + id));
req.applyTo(entity);
nodeGroupRepository.save(entity);
return NodeGroupDto.Response.from(entity);
}
🤖 Prompt for AI Agents
In src/main/java/com/handongapp/cms/service/impl/NodeGroupServiceImpl.java
around lines 74 to 79, after modifying the entity with req.applyTo(entity), the
changes are not saved to the database. Fix this by calling
nodeGroupRepository.save(entity) after applying the updates to persist the
changes before returning the response.

Comment on lines 48 to 53
public SectionDto.Response update(String id, SectionDto.UpdateRequest req) {
TbSection entityToUpdate = sectionRepository.findByIdAndDeleted(id, "N")
TbSection entity = sectionRepository.findByIdAndDeleted(id, "N")
.orElseThrow(() -> new EntityNotFoundException("Section not found with id: " + id));

String courseId = entityToUpdate.getCourseId();

// Apply changes from DTO. Assumes req.applyTo updates entityToUpdate.order if req.getOrder() is not null.
req.applyTo(entityToUpdate);

// entityToUpdate.getOrder() will be the requested new order if specified in DTO, or original order if not.
TbSection updatedEntity = reorderAndPersist(courseId, entityToUpdate, entityToUpdate.getOrder());
return SectionDto.Response.from(updatedEntity);
req.applyTo(entity);
return SectionDto.Response.from(entity);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

엔티티 변경사항이 저장되지 않습니다.

req.applyTo(entity)로 엔티티를 수정한 후 저장하지 않고 있습니다.

다음과 같이 수정하세요:

 public SectionDto.Response update(String id, SectionDto.UpdateRequest req) {
     TbSection entity = sectionRepository.findByIdAndDeleted(id, "N")
             .orElseThrow(() -> new EntityNotFoundException("Section not found with id: " + id));
     req.applyTo(entity);
+    sectionRepository.save(entity);
     return SectionDto.Response.from(entity);
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
public SectionDto.Response update(String id, SectionDto.UpdateRequest req) {
TbSection entityToUpdate = sectionRepository.findByIdAndDeleted(id, "N")
TbSection entity = sectionRepository.findByIdAndDeleted(id, "N")
.orElseThrow(() -> new EntityNotFoundException("Section not found with id: " + id));
String courseId = entityToUpdate.getCourseId();
// Apply changes from DTO. Assumes req.applyTo updates entityToUpdate.order if req.getOrder() is not null.
req.applyTo(entityToUpdate);
// entityToUpdate.getOrder() will be the requested new order if specified in DTO, or original order if not.
TbSection updatedEntity = reorderAndPersist(courseId, entityToUpdate, entityToUpdate.getOrder());
return SectionDto.Response.from(updatedEntity);
req.applyTo(entity);
return SectionDto.Response.from(entity);
}
public SectionDto.Response update(String id, SectionDto.UpdateRequest req) {
TbSection entity = sectionRepository.findByIdAndDeleted(id, "N")
.orElseThrow(() -> new EntityNotFoundException("Section not found with id: " + id));
req.applyTo(entity);
sectionRepository.save(entity);
return SectionDto.Response.from(entity);
}
🤖 Prompt for AI Agents
In src/main/java/com/handongapp/cms/service/impl/SectionServiceImpl.java around
lines 48 to 53, after modifying the entity with req.applyTo(entity), the changes
are not saved to the database. Fix this by calling
sectionRepository.save(entity) after applying the updates to persist the changes
before returning the response.

Comment on lines 57 to 61
public void deleteSoft(String id) {
TbSection entity = sectionRepository.findByIdAndDeleted(id, "N")
.orElseThrow(() -> new EntityNotFoundException("Section not found with id: " + id));

String courseId = entity.getCourseId();
entity.setDeleted("Y");
entity.setOrder(null); // Mark order as irrelevant for soft-deleted items
sectionRepository.save(entity); // Persist the soft deletion

// Reorder remaining active sections
reorderAndPersist(courseId, null, null);
}

private TbSection reorderAndPersist(String courseId, @Nullable TbSection targetSection, @Nullable Integer requestedOrderForTarget) {
List<TbSection> currentSectionsInDb = sectionRepository.findByCourseIdAndDeletedOrderByOrderAsc(courseId, "N");

List<TbSection> sectionsToProcess = new ArrayList<>();
boolean isTargetNew = (targetSection != null && targetSection.getId() == null);

// Populate sectionsToProcess with existing sections, excluding the targetSection if it's being updated
for (TbSection s : currentSectionsInDb) {
if (targetSection != null && s.getId() != null && s.getId().equals(targetSection.getId()) && !isTargetNew) {
// Skip the old version of targetSection if it's an update of an existing entity
continue;
}
sectionsToProcess.add(s);
}

// If targetSection is provided (create or update), add it to the list at the correct position
// Keep a reference to return, as the instance in targetSection variable might be the one from DB
// or a new one. The one added to sectionsToProcess is what gets its ID populated if new.
TbSection sectionToReturn = targetSection;

if (targetSection != null) {
int insertionIndex;
Integer effectiveOrder = requestedOrderForTarget;

// If no order is specified in the request for an existing item,
// use its current order to maintain its relative position unless other items shift it.
if (effectiveOrder == null) {
if (!isTargetNew) { // Existing item, order not specified in update DTO
effectiveOrder = targetSection.getOrder(); // Use its current order for placement logic
}
// If still null (e.g., new item and DTO order was null), it will be appended.
}

if (effectiveOrder == null) {
insertionIndex = sectionsToProcess.size(); // Append to the end
} else {
// Ensure insertionIndex is within the bounds of [0, sectionsToProcess.size()]
insertionIndex = Math.max(0, Math.min(effectiveOrder, sectionsToProcess.size()));
}
sectionsToProcess.add(insertionIndex, targetSection);
}

// Re-assign sequential order values from 0 to the items in sectionsToProcess
for (int i = 0; i < sectionsToProcess.size(); i++) {
TbSection section = sectionsToProcess.get(i);
section.setOrder(i);
}

if (!sectionsToProcess.isEmpty()) {
sectionRepository.saveAll(sectionsToProcess); // Use sectionsToProcess directly
}

// If targetSection was new, its ID is populated by saveAll.
// The 'sectionToReturn' (which is the 'targetSection' object passed in or created)
// is the instance that was added to sectionsToProcess and subsequently saved.
// So it should have the ID if it was new.
return sectionToReturn;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

소프트 삭제가 저장되지 않습니다.

엔티티의 deleted 플래그를 설정한 후 저장하지 않고 있습니다.

다음과 같이 수정하세요:

 public void deleteSoft(String id) {
     TbSection entity = sectionRepository.findByIdAndDeleted(id, "N")
             .orElseThrow(() -> new EntityNotFoundException("Section not found with id: " + id));
     entity.setDeleted("Y");
+    sectionRepository.save(entity);
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
public void deleteSoft(String id) {
TbSection entity = sectionRepository.findByIdAndDeleted(id, "N")
.orElseThrow(() -> new EntityNotFoundException("Section not found with id: " + id));
String courseId = entity.getCourseId();
entity.setDeleted("Y");
entity.setOrder(null); // Mark order as irrelevant for soft-deleted items
sectionRepository.save(entity); // Persist the soft deletion
// Reorder remaining active sections
reorderAndPersist(courseId, null, null);
}
private TbSection reorderAndPersist(String courseId, @Nullable TbSection targetSection, @Nullable Integer requestedOrderForTarget) {
List<TbSection> currentSectionsInDb = sectionRepository.findByCourseIdAndDeletedOrderByOrderAsc(courseId, "N");
List<TbSection> sectionsToProcess = new ArrayList<>();
boolean isTargetNew = (targetSection != null && targetSection.getId() == null);
// Populate sectionsToProcess with existing sections, excluding the targetSection if it's being updated
for (TbSection s : currentSectionsInDb) {
if (targetSection != null && s.getId() != null && s.getId().equals(targetSection.getId()) && !isTargetNew) {
// Skip the old version of targetSection if it's an update of an existing entity
continue;
}
sectionsToProcess.add(s);
}
// If targetSection is provided (create or update), add it to the list at the correct position
// Keep a reference to return, as the instance in targetSection variable might be the one from DB
// or a new one. The one added to sectionsToProcess is what gets its ID populated if new.
TbSection sectionToReturn = targetSection;
if (targetSection != null) {
int insertionIndex;
Integer effectiveOrder = requestedOrderForTarget;
// If no order is specified in the request for an existing item,
// use its current order to maintain its relative position unless other items shift it.
if (effectiveOrder == null) {
if (!isTargetNew) { // Existing item, order not specified in update DTO
effectiveOrder = targetSection.getOrder(); // Use its current order for placement logic
}
// If still null (e.g., new item and DTO order was null), it will be appended.
}
if (effectiveOrder == null) {
insertionIndex = sectionsToProcess.size(); // Append to the end
} else {
// Ensure insertionIndex is within the bounds of [0, sectionsToProcess.size()]
insertionIndex = Math.max(0, Math.min(effectiveOrder, sectionsToProcess.size()));
}
sectionsToProcess.add(insertionIndex, targetSection);
}
// Re-assign sequential order values from 0 to the items in sectionsToProcess
for (int i = 0; i < sectionsToProcess.size(); i++) {
TbSection section = sectionsToProcess.get(i);
section.setOrder(i);
}
if (!sectionsToProcess.isEmpty()) {
sectionRepository.saveAll(sectionsToProcess); // Use sectionsToProcess directly
}
// If targetSection was new, its ID is populated by saveAll.
// The 'sectionToReturn' (which is the 'targetSection' object passed in or created)
// is the instance that was added to sectionsToProcess and subsequently saved.
// So it should have the ID if it was new.
return sectionToReturn;
}
public void deleteSoft(String id) {
TbSection entity = sectionRepository.findByIdAndDeleted(id, "N")
.orElseThrow(() -> new EntityNotFoundException("Section not found with id: " + id));
entity.setDeleted("Y");
sectionRepository.save(entity);
}
🤖 Prompt for AI Agents
In src/main/java/com/handongapp/cms/service/impl/SectionServiceImpl.java around
lines 57 to 61, the method sets the deleted flag on the entity but does not save
the updated entity to the repository. To fix this, after setting
entity.setDeleted("Y"), call sectionRepository.save(entity) to persist the
change.

@junglesub junglesub merged commit 7f748d4 into main Jun 6, 2025
2 checks passed
@github-project-automation github-project-automation bot moved this from In review to Done in HANDONG-CMS Jun 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

be Backend

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants